/**
 * 余额明细
 */
import 'package:cbec_app/components/base/base_page.dart';
import 'package:cbec_app/components/common/common_style.dart';
import 'package:cbec_app/components/base/base_nav_bar.dart';
import 'package:cbec_app/components/common/not_found.dart';
import 'package:cbec_app/pages/my/controller/withdraw_ctr.dart';
import 'package:cbec_app/utils/Tools.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class SurplusDetail extends GetView<WithDrawController> {
  const SurplusDetail({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<WithDrawController>(builder: (controller){
      return BasePage(
      title: "余额明细",
      iconType: IconType.back,
      children: [
        Container(
          child: Column( 
                children: [
                  tab(),
                  Container(
                    height: 570.h,
                    color: Colors.white,
                    margin: EdgeInsets.only(top: 10.w),
                    child: controller.withdrawLogList.isNotEmpty?Tools.getPullRefresh(
                      enablePullDown: true,
                      enablePullUp: controller.hasNextPage,
                      refreshController: controller.baseRefreshCtr,
                      onRefresh: controller.onPageRefresh,
                      onLoading: controller.onPageLoading,
                      child:ListView.builder(
                        itemCount: controller.withdrawLogList.length,
                        itemBuilder: (context,index){
                          final Map item = controller.withdrawLogList[index];
                        return AmountLogItem(item: item);
                      })
                    ):const NotFound()
                  )
                ],
              ),
        )
      ],
    );
    });
  }

  Widget tab(){
    return Container(
      color: Colors.white,
      child: TabBar(
        controller: controller.tabController,
          indicator: BoxDecoration(
              border: Border(
                  bottom:
                      BorderSide(color: Colors.red, width: 1.0))),
          labelColor: Colors.red,
          labelPadding: EdgeInsets.zero,
          tabs: [
            Tab(text: '全部'),
            Tab(text: '收入'),
            Tab(text: '支出'),
          ]),
    );
  }
}

/**
 * 金额文本组件
 */
class AmountLogItem extends StatelessWidget {

    // final String title;//标题
    // final String surplus;//剩余金额
    // final String orderSn;//订单号
    // final String time;//金额时间
    // final String amount;//金额
    // final bool status;//类型 true是收入 false是支出

    final Map item;

  const AmountLogItem({
        super.key,
        // required this.title,
        // required this.surplus,
        // required this.orderSn,
        // required this.time,
        // required this.amount,
        // required this.status, 
        required this.item
    });
    final TextStyle titleStyle = const TextStyle(fontSize: 12,fontWeight: FontWeight.bold,color: Colors.black);
    final TextStyle surplusTitleStyle = const TextStyle(fontSize: 10,fontWeight: FontWeight.bold,color: Colors.black);
    final TextStyle subTitleStyle = const TextStyle(fontSize: 10,fontWeight: FontWeight.w400,color: Color.fromRGBO(153, 153, 153, 1));
    final TextStyle amountAddTitleStyle = const TextStyle(fontSize: 14,fontWeight: FontWeight.w700,color: Color.fromRGBO(7, 193, 96, 1));
    final TextStyle amountdecTitleStyle = const TextStyle(fontSize: 14,fontWeight: FontWeight.w700,color: Color.fromRGBO(248, 63, 45, 1));

  @override
  Widget build(BuildContext context) {
    String _type = '+';
    TextStyle _amountColor = amountAddTitleStyle;
    if(item['type']==0){
        _type = '+';
         _amountColor = amountAddTitleStyle;
    }else{
        _type = '-';
         _amountColor = amountdecTitleStyle;
    }

    return Container(
      padding: EdgeInsets.all(18.w),
      decoration: bottom_gary_border,
      // height: 90.h,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          //左边是4列的文本
          SizedBox(
            // alignment: Alignment.topLeft,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(item['reason'],style: titleStyle,),
                SizedBox(height: 5.h,),
                Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [Text("到账后余额:",style: subTitleStyle,), Text("￥${item['money']}",style: surplusTitleStyle,)],
                ),
                SizedBox(height: 5.h,),
                Text("订单编号:${item['sn']}",style: subTitleStyle,),
                SizedBox(height: 5.h,),
                Text(item['cd'],style: subTitleStyle,),
              ],
            ),
          ),
          //右边的数字
          SizedBox(
            child: Text("$_type${item['amount']}",style: _amountColor),
          )
        ],
      ),
    );
  }
}
